package com.shaifish.common_sys.controller;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shaifish.common_sys.base.BaseEntity;
import com.shaifish.common_sys.base.BaseServiceImpl;
import com.shaifish.common_sys.common.Query;
import com.shaifish.common_sys.common.R;
import com.shaifish.common_sys.wrapper.BaseWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Base控制器
 * @author ShaiFish
 */
public class BaseController<V, T extends BaseEntity, M extends BaseMapper<T>, S extends BaseServiceImpl<M, T>, W extends BaseWrapper<T, V>> {

    @Autowired
    private HttpServletRequest request;

    @Resource
    S s;

    @Resource
    W w;

    /**
     * 通用分页接口
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询接口", notes = "分页查询")
    public R<IPage<V>> page(Query query) {
        IPage<T> page = new Page<>(query.getPage(), query.getPageSize());
        s.page(page);
        return R.data(w.pageVO(page));
    }








    /**
     * 通用分页接口
     * @param v
     * @param query
     * @return
     */
//    @PostMapping("/page")
//    @ApiOperation(value = "分页查询接口", notes = "分页查询")
//    public R<IPage<V>> page(V v, Query query) {
//        // v用于构造查询条件 可扩展Wrapper
//        IPage<T> page = new Page<>(query.getPage(), query.getPageSize());
//        s.page(page);
//        return R.data(w.pageVO(page));
//    }


}
